﻿using ConsoleApp2.Enum;
using System.Collections.Generic;

namespace ConsoleApp2.Models;

public class LocalPermission
{
    public static List<Permission> Permissions { get; set; }

    public LocalPermission()
    {
        LoadPermissions();
    }

    public static List<Permission> GetLocalPermissions()
    {
        if (Permissions == null)
        {
            Permissions = new List<Permission>();
            LoadPermissions();
        }

        return Permissions;
    }

    private static void LoadPermissions()
    {
        // 用户管理权限
        AddPermission(PermissionName.AddUser, "添加用户");
        AddPermission(PermissionName.UpdateUser, "修改用户");
        AddPermission(PermissionName.DeleteUser, "删除用户");
        AddPermission(PermissionName.QueryUser, "查询用户");

        // 角色管理权限
        AddPermission(PermissionName.AddRole, "添加角色");
        AddPermission(PermissionName.UpdateRole, "修改角色");
        AddPermission(PermissionName.DeleteRole, "删除角色");
        AddPermission(PermissionName.QueryRole, "查询角色");

        // 权限管理权限
        AddPermission(PermissionName.AddPermission, "添加权限");
        AddPermission(PermissionName.UpdatePermission, "修改权限");
        AddPermission(PermissionName.DeletePermission, "删除权限");
        AddPermission(PermissionName.QueryPermission, "查询权限");
    }

    private static void AddPermission(PermissionName permissionName, string nickName)
    {
        Permission permission = new Permission()
        {
            PermissionName = permissionName,
            CreateTime = System.DateTime.Now,
            UpdateTime = System.DateTime.Now,
            IsDeleted = false,
            NickPermissionName = nickName
        };
        Permissions.Add(permission);
    }
}